﻿using System;

namespace Alex.Library.Log
{
    /// <summary>
    /// 日志基类
    /// </summary>
    public abstract class LoggerBase : ILogger
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public LoggerBase() 
        {
            this.Template = new DefaultTemplate();
            this.FlushLevel = LogLevel.DEBUG;
        }

        /// <summary>
        /// 输出日志的最低级别，DEBUG->INFO->WARN->ERROR->FATAL
        /// </summary>
        public LogLevel FlushLevel { get; set; }

        /// <summary>
        /// 日志模板
        /// </summary>
        public ILogInfoTemplate Template { get; set; }

        /// <summary>
        /// 将经过筛选的日志输出
        /// </summary>
        /// <param name="level">日志级别</param>
        /// <param name="message">消息</param>
        protected abstract void DoFlush(LogLevel level, string message);

        /// <summary>
        /// 输出日志
        /// </summary>
        /// <param name="level">级别</param>
        /// <param name="message">消息</param>
        public virtual void Flush(LogLevel level, string message)
        {
            if (level >= this.FlushLevel)
            {
                DoFlush(level, message);
            }
        }
    }
}
